﻿using System;
using System.Collections.Generic;

namespace YArchitech.LIB
{
	public class ListSortByNumber : IComparer<string>
	{
		int IComparer<string>.Compare(string x, string y)
		{
			if (x == null || y == null)
			{
				throw new ArgumentException("Parameters can't be null");
			}
			char[] array = x.ToCharArray();
			char[] array2 = y.ToCharArray();
			int i = 0;
			int num = 0;
			while (i < array.Length && num < array2.Length)
			{
				if (char.IsDigit(array[i]) && char.IsDigit(array2[num]))
				{
					string text = "";
					string text2 = "";
					while (i < array.Length)
					{
						if (!char.IsDigit(array[i]))
						{
							break;
						}
						text += array[i].ToString();
						i++;
					}
					while (num < array2.Length && char.IsDigit(array2[num]))
					{
						text2 += array2[num].ToString();
						num++;
					}
					if (int.Parse(text) > int.Parse(text2))
					{
						return 1;
					}
					if (int.Parse(text) < int.Parse(text2))
					{
						return -1;
					}
				}
				else
				{
					if (array[i] > array2[num])
					{
						return 1;
					}
					if (array[i] < array2[num])
					{
						return -1;
					}
					i++;
					num++;
				}
			}
			if (array.Length == array2.Length)
			{
				return 0;
			}
			if (array.Length <= array2.Length)
			{
				return -1;
			}
			return 1;
		}
	}
}
